package com.xxl.job.admin.controller.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * @Author: Zhihj
 * @Date: 2023-10-12 22:13:48
 */
@Component
public class CookieInterceptor implements HandlerInterceptor {

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        if(modelAndView != null && request.getCookies() != null && request.getCookies().length >0){
            HashMap<String,Cookie> cookieMap = new HashMap<>();
            for (Cookie ck : request.getCookies()) {
                cookieMap.put(ck.getName(),ck);
            }
            modelAndView.addObject("cookieMap", cookieMap);
        }
        // static method
//        if (modelAndView != null) {
//            modelAndView.addObject("I18nUtil", FtlUtil.generateStaticModel(I18nUtil.class.getName()));
//        }

    }
}
